import {productMethod} from '@/utils/models/product.js'
const crudMethod = new productMethod();
import {homeMethod} from '@/utils/models/index.js'
const indexMethod = new homeMethod();
import Footer from '@/components/footer-main'
export default {
  name: 'Home',
  components: { Footer},
  data() {
    return {
      productLoad: false,
      productData: [],
      productId: null,
      bannerData: [],
      dictionaryData: []
    }
  },
  created() {
    document.title = '朔悦产品'
    this.getCmfBanner()
    this.getProducts()
    this.getDictionarys()
  },
  methods: {
    getCmfBanner () {
      let _this = this
      _this.bannerData = []
      indexMethod.frontCmfBanner(1).then((res) => {
        let {msg, code, data} = res;
        data.data.forEach(item => {
          item.bannerImg = item.bannerImg ? _this.baseURL + item.bannerImg : ''
        })
        _this.bannerData = data.data
      })
    },
    getDictionarys() {
      let _this = this
      indexMethod.getDictionary('Banner分类').then((res) => {
        let {msg, code, data} = res;
        data.data.forEach(item => {
          if(item.parentId === '105001') {
            _this.dictionaryData.push(item)
          }
        })
      })
    },
    getProducts () {
      let _this = this
      _this.productLoad = true
      crudMethod.getProduct().then((res) => {
        _this.productLoad = false
        let {msg, code, data} = res;
        data.data.forEach(item => {
          item.productMinImg = item.productMinImg ? item.productMinImg.split(',') : []
        })
        _this.productData = data.data
        _this.productId = data.data[0].productId
      })
    },
    handleMouseover(id) {
      this.productId = id
    }
  }
}
